
//
//  LoveListenCollectionViewCellOfContentViewFirst.m
//  XYFMApp
//
//  Created by 岁变 on 16/8/31.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "LoveListenCollectionViewCellOfContentViewFirst.h"
#import "XYMacro.h"

@interface LoveListenCollectionViewCellOfContentViewFirst () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) UIView *customSetUpView;
@property (nonatomic, strong) UIButton *setUpButton;
@property (nonatomic, strong) UILabel *numberLabel;

@end

@implementation LoveListenCollectionViewCellOfContentViewFirst

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCustomSetUpView];
        [self createContentTableView];
    }
    return self;
}

- (void)createCustomSetUpView {
    
    _customSetUpView = [[UIView alloc] initWithFrame:CGRectZero];
    _customSetUpView.backgroundColor = [UIColor colorWithRed:0.12 green:0.14 blue:0.15 alpha:1.00];
    [self.contentView addSubview:_customSetUpView];
    [_customSetUpView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.mas_offset(40);
    }];
    
    _setUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_setUpButton setTitle:@"批量处理" forState:UIControlStateNormal];
    [_setUpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _setUpButton.titleLabel.font = [UIFont systemFontOfSize:14];
//    [_setUpButton addTarget:self action:@selector(setUp:) forControlEvents:UIControlEventTouchUpInside];
    [_customSetUpView addSubview:_setUpButton];
    [_setUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_customSetUpView.mas_top).with.offset(5);
        make.bottom.equalTo(_customSetUpView.mas_bottom).with.offset(-5);
        make.right.equalTo(_customSetUpView.mas_right).with.offset(-15);
        make.width.mas_offset(80);
    }];
    
    _numberLabel = [[UILabel alloc] init];
//    _numberLabel.text = [NSString stringWithFormat:@"订阅总数(%ld)", number];
    _numberLabel.textColor = [UIColor whiteColor];
    _numberLabel.textAlignment = NSTextAlignmentCenter;
    _numberLabel.font = [UIFont systemFontOfSize:14];
    [_customSetUpView addSubview:_numberLabel];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_customSetUpView.mas_top).with.offset(5);
        make.bottom.equalTo(_customSetUpView.mas_bottom).with.offset(-5);
        make.left.equalTo(_customSetUpView.mas_left).with.offset(15);
        make.width.mas_offset(80);
    }];
    
    
}

- (void)createContentTableView {
    _tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[LoveListenTableViewCellFirst class] forCellReuseIdentifier:@"LoveListenTableViewCellFirst"];
    [self.contentView addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(40);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _model.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LoveListenTableViewCellFirst *cell = [tableView dequeueReusableCellWithIdentifier:@"LoveListenTableViewCellFirst" forIndexPath:indexPath];
    LoveListenModelFirstData *model = [_model.data objectAtIndex:indexPath.row];
    cell.model = model;
    cell.myIndexPath = indexPath;
    cell.modelArr = (NSMutableArray *)_model.data;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    VCOfDiscoverList *nextVC = [[VCOfDiscoverList alloc] init];
    VCOfLoveListen *currentVC = (VCOfLoveListen *)self.nextResponder.nextResponder.nextResponder;
    LoveListenModelFirstData *model = [_model.data objectAtIndex:indexPath.row];
    nextVC.item_id = [NSString stringWithFormat:@"%ld", model.item_id];
    [currentVC.navigationController pushViewController:nextVC animated:YES];

}


- (void)setModel:(LoveListenModelFirst *)model {
    _model = [[LoveListenModelFirst alloc] init];
    _model = model;
    [_tableView reloadData];
}


@end
